﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media.Animation;

namespace Views
{
    /// <summary>
    /// ShowMessagePanel.xaml 的交互逻辑
    /// </summary>
    public partial class ShowMessagePanel : UserControl
    {
        public ShowMessagePanel()
        {
            InitializeComponent();
        }

        public void ShowLog(string mes)
        {
            this.ShowText.Text = mes;
            this.Visibility = Visibility.Visible;
            Canvas canvas = (Canvas)this.Parent;
            this.SetValue(Canvas.LeftProperty, (canvas.ActualWidth - 200) / 2);
            this.SetValue(Canvas.TopProperty, canvas.ActualHeight / 2);

            DoubleAnimation animation = new DoubleAnimation();
            animation.BeginTime = TimeSpan.FromSeconds(2);
            animation.Completed += Animation_Completed;
            animation.FillBehavior = FillBehavior.Stop;
            animation.To = 0;
            this.BeginAnimation(Canvas.TopProperty, animation);
        }

        private void Animation_Completed(object sender, EventArgs e)
        {
            Canvas canvas = (Canvas)this.Parent;
            canvas.Children.Remove(this);
        }
    }
}